// 文件位置: ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/DroneTestController.java
package com.ruoyi.web.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;

@RestController
@RequestMapping("/system/drone/test")
public class DroneTestController extends BaseController {

    @Value("${drone.service.url:http://localhost:5002}")
    private String droneServiceUrl;

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/connection")
    public AjaxResult testConnection() {
        try {
            String url = droneServiceUrl + "/health";
            ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);

            return AjaxResult.success("连接成功", response.getBody());
        } catch (Exception e) {
            return AjaxResult.error("连接失败: " + e.getMessage());
        }
    }

    @GetMapping("/droneStatus")
    public AjaxResult testDroneStatus() {
        try {
            String url = droneServiceUrl + "/drone/status";
            ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);

            return AjaxResult.success("获取状态成功", response.getBody());
        } catch (Exception e) {
            return AjaxResult.error("获取状态失败: " + e.getMessage());
        }
    }
}
